package com.fanbuchi.fukua.widget;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.TextView;
import java.sql.Date;

/**
 * Created by killerzhangsan on 2015/5/28.
 * @title  timetext系统控件
 */
public class TimeTextView extends TextView {

    public static final String format_24_yMdkms="yyyy-MM-dd kk:mm:ss";

    public static final String format_24_Mdkms="MM-dd kk:mm";



    public TimeTextView(Context context) {
        this(context, null);
    }

    public TimeTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public TimeTextView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
    public TimeTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    /**
     *
     * @param format yyyy-MM-dd hh:mm:ss 12
     * @param format yyyy-MM-dd kk:mm:ss 24
     * @param time
     */
    public void setTimeTextView(String format,long time){
       CharSequence strChar=null;
       try {
           strChar= android.text.format.DateFormat.format(format,time);
       }catch (Exception e){
           e.printStackTrace();
       }
        setText(strChar==null?new Date(time).toString():strChar);
    }

    public void setTimeTextView(long time){
        setTimeTextView(format_24_Mdkms,time);
    }


}
